#pragma once

#ifdef __cplusplus
extern "C"
{
#endif

#include <stdint.h>
#include <stdlib.h>

#define THREADPOOL_FOREACH_ERR(X)               \
    X(0, SUCCESS, "Success")                    \
    X(-1, ERR_ARG, "Invalid argument")          \
    X(-2, ERR_MEM, "Memory allocation failed")  \
    X(-3, ERR_AGAIN, "again operation")         \
    X(-6, ERR_QUEUE_FULL, "Task queue is full") \
    X(-16, ERR_OTHER, "Other error")

enum
{
#define X(code, name, msg) THREADPOOL_RET_##name = code,
    THREADPOOL_FOREACH_ERR(X)
#undef X
};

typedef struct _threadtask_t threadtask_t;
typedef struct _fix_threadpool_t fix_threadpool_t;

fix_threadpool_t *fix_threadpool_create(size_t thread_capacity, size_t queue_size);
int32_t fix_threadpool_destroy(fix_threadpool_t *pool);
int32_t fix_threadpool_addtask(fix_threadpool_t *pool, void (*function)(void *), void *arg);
const char *fix_threadpool_strerror(int err);

#ifdef __cplusplus
}
#endif
